/*顾客状态值有5个：possible(可能到来)，waiting(正在等待的状态)，ready(正在点菜)，eating(正在吃饭的状态)，impossible（今天不可能到来）*/
let customer = {
    0: {
        name: "Chen",
        status: "possible",
        img: "./img/customer0.png"
    },
    1: {
        name: "Tai",
        status: "possible",
        img: "./img/customer1.png"
    },
    2: {
        name: "Hong",
        status: "possible",
        img: "./img/customer2.png"
    },
    3: {
        name: "LI",
        status: "possible",
        img: "./img/customer3.png"
    },
    4: {
        name: "ZHOU",
        status: "possible",
        img: "./img/customer4.png"
    },
    5: {
        name: "XI",
        status: "possible",
        img: "./img/customer5.png"
    },
    6: {
        name: "Yan",
        status: "possible",
        img: "./img/customer6.png"
    },
}
/*有四张桌子*/
let table = {
    0: {
        list: [],//用于记录菜单
        total: 0,
        canUse: true,//是否可以使用该桌子
        userID: 0,//绑定的用户的id
        money: 0,//该桌的总钱
        dealCount: 0//计算一共吃了多少个菜
    },
    1: {
        list: [],
        total: 0,
        canUse: true,
        userID: 0,
        money: 0,
        dealCount: 0
    },
    2: {
        list: [],
        total: 0,
        canUse: true,
        userID: 0,
        money: 0,
        dealCount: 0
    },
    3: {
        list: [],
        total: 0,
        canUse: true,
        userID: 0,
        money: 0,
        dealCount: 0
    }
};
/*设置四种颜色*/
let color = [
    { color1: "b20000", color2: "ff2020", status: true },
    { color1: "00af00", color2: "80ff00", status: true },
    { color1: "d96d00", color2: "ff9122", status: true },
    { color1: "7a4dff", color2: "ac91ff", status: true }
];
/*厨师列表*/
let chef = {
    0: {
        status: "free" 
    },
    1: {
        status: "free" //free和busy两种状态
    }
}
/*菜品*/
let dishes = {
    0: {
        name: "凉拌SAN",
        type: "liangCai",
        price: 22,//标价
        originPrice:4//成本价
    },
    1: {
        name: "冷切DOM",
        type: "liangCai",
        price: 44,
        originPrice:2
    },
    2: {
        name: "UL抄LI",
        type: "zhuCai",
        price: 62,
        originPrice:12
    },
    3: {
        name: "红烧HEAD",
        type: "zhuCai",
        price: 45,
        originPrice:6
    },
    4: {
        name: "酥炸Table",
        type: "zhuCai",
        price: 34,
        originPrice:5
    },
    5: {
        name: "炙烤CSS",
        type: "zhuCai",
        price: 16,
        originPrice:2
    },
    6: {
        name: "清蒸DIV",
        type: "zhuCai",
        price: 22,
        originPrice:5
    },
    7: {
        name: "鲜榨flex",
        type: "yinPin",
        price: 25,
        originPrice:6
    },
    8: {
        name: "小程序奶茶",
        type: "yinPin",
        price: 16,
        originPrice:2
    }
};
//做菜的列表
let cookingList = []
//做完菜的列表
let finishCookList = []
//开始下一个的开始时间
let startPadding =100
//改变下一个的时间
let changePadding = 20
//做菜的时间
const cookingTime = 5000
//吃饭的时间
const eatingTime = 5000
//顾客等待的时间
const cusWaitingTime = 10000
//顾客等待时间的改变
let cusWaitingChange = 5;
//转变做菜的时间
const cookingChange = 20
//转变顾客等待的时间
const eatingChange = 20
//吃饭的人数
let eatingNumber = 0
//厨师的个数
let cookCount  = 0
//星期的count
let weekendCount = 1
//天数的计数
let dayCount =1
//正在等待顾客的列表
let waitingList =[]
//厨师的个数
let chefNumber = 2
//菜单列表的提交
let sumbitButtonListener = null
//取出按钮
let quitButtonLister = null
//解雇厨师
let fireChef= null
//删除蒸菜等待顾客的列表
let removeWaiting = null
//时间
let date = new Date()
//指针
let point =0
//删除厨师的事件的监听
let delChefButtonListener = null
//确认解雇厨师的按钮
let fireChefButtonListener= null;
//添加style的样式的选择
//因为同时复用一个样式时，其他可能不是很美观，则可以通过这种方式来进行
//单独的设置自己所需要的样式
let cssNode = document.createElement("style")
cssNode.id = "HTT_Style"
cssNode.setAttribute("type","text/css")
cssNode.innerHTML = "* {\n" +
    "    font-family: Arial, Helvetica, sans-serif;\n" +
    "}";
document.body.appendChild(cssNode)
//开始经营
const start = $("start")
console.log(start);
//添加厨师
let add_chef = $("add-chef-icon")
//厨师页面的打开
let addChefPage = $("addChef")
//解雇页面的打开
let fireDiv = $("fire")
//星期的计算
let weekend = $("weekend")
//天数的计算
let day = $("day")
//总数
let income = $("all_money")
//添加开始的点击事件
start.addEventListener("click",init)
//监听添加厨师的按钮
add_chef.addEventListener("click",addChef)

//初始化函数
function init(){
    console.log("开始游戏");
    //关闭开始视窗
    const open = $("open")
    open.style.display ="none"
    let id = 0;
    const waitingTime = 2000;//等待事件是2秒
    const comingTime = 3000;//下一个顾客来是3秒
    ElMessage("warning","餐厅目前还有空位，赶紧点击等位的顾客进行就餐",2000)
    waitingList.push(id);//将其放在等待的列表里面
    customer[id].status="possible"//首先设置，该顾客是会到来的
    newCustomer(id,waitingTime)//新顾客的到来 
    //三秒钟过来一个顾客
    let timer =  setInterval(()=>{
        if(id<6){
            id++;
            waitingList.push(id);
            customer[id].status="possible"
            newCustomer(id,waitingTime);//在html里面增加
        }else{
            clearInterval(timer)
        }
    },comingTime)
}
//定时调用厨房的处理
setInterval(() => {
    if (cookingList.length > 0) {
        handerKitchen();
    }
}, 100);
//设置时间的计算
setInterval(()=>{
    let nextday = true;
    //判断是否可以进进入下一天
    //假如每个顾客里面有其他状态的话，不能进入下一天，要等全部的各科离开之后才可以进入下一天

    for(let i in customer){
        if(customer[i].status !=="impossible"){
            nextday = false;
        }
    }
    for(let i in chef){
        if(chef[i].status !=="free"){
            nextday = false;
        }
    }
    if(nextday){
        let income = $("all_momey")
        startPadding = 100;
        let clearWaitArea = $("wait-box");
        clearWaitArea,innerHTML = "";
        //将在等候区的人员进行清空进入下一天
        dayCount++;
        day.innerHTML="D" + dayCount;
        //重新进行初始化
        init();
        if(dayCount % 7 ===0){
            weekendCount++;
            weekend.innerHTML = "w" + weekendCount;
            let updateMoney = parseInt(income.innerHTML) - (chefNumber*100);
            income.innerHTML = updateMoney;
        }
    }else if(nextday){
        ElMessage("warning","餐厅因经营不善倒闭，请重新刷新页面重新开始！",3000)

    }
},20000)
//添加厨师
function addChef(){
    console.log("111");
    addChefPage.style.display = "flex";
    let newStyle = ".bar div{padding:0 1rem}";
    addStyle(newStyle);
    let yes_btn = $("yes-btn");
    let no_btn = $("no-btn");
    yes_btn.addEventListener("click",comfirmBtn);
    no_btn.addEventListener("click",quitAddBtn);
}
